package Breeze

import breeze.linalg.{DenseMatrix, DenseVector}

object HellowBreeze {
  def main(args: Array[String]): Unit = {
    //全零向量
    val z0 = DenseVector.ones[Double](5)

    val z1 = DenseVector.ones[Double](5)

    println(z0)
    //DenseVector(1.0, 1.0, 1.0, 1.0, 1.0)

    //全一向量
    val o = DenseVector.ones[Double](5)

    println(o)
    //DenseVector(1.0, 1.0, 1.0, 1.0, 1.0)

    val vector1: DenseVector[Double] = o * 5.0

    val vector2: DenseVector[Double] = o + vector1

    println(vector1)
    //DenseVector(5.0, 5.0, 5.0, 5.0, 5.0)

    //添加元素到向量
    val f = DenseVector.fill(3)(5)

    println(f)
    //DenseVector(5, 5, 5)

    //添加向量（指定范围和步长）
    val r = DenseVector.range(1, 10, 2)

    println(r)
    //DenseVector(1, 3, 5, 7, 9)

    val dr = DenseVector.rand(4)

    println(dr)
    //DenseVector(0.5237886556744307, 0.17101823548770168, 0.8903893686595532, 0.4922883546085435)

    val d1:DenseVector[Double] = dr + 1.0
    //DenseVector(15.237886556744307, 11.710182354877016, 18.90389368659553, 14.922883546085435)

    val d2:DenseVector[Double] = d1 * 10.0

    println(d2)
    //DenseVector(15.237886556744307, 11.710182354877016, 18.90389368659553, 14.922883546085435)

    //从函数创建向量
    val dt = DenseVector.tabulate(3)(i => i * 3)

    println(dt)
    //DenseVector(0, 3, 6)

    //按行生成向量
    val v0 = DenseVector(1, 2, 3, 4, 5)
    val v1 = DenseVector(Array(1, 2, 3, 4, 5))
    val v2 = DenseVector((1, 2, 3, 4, 5))

    //向量转置
    val t1 = v0.t

    println(t1)
    //Transpose(DenseVector(1, 2, 3, 4, 5))

    ///////////////////////////////////////
    //////////////////矩阵//////////////////
    ///////////////////////////////////////

    //全零矩阵
    val mz = DenseMatrix.zeros[Int](5, 3)

    println(mz)
    //0  0  0
    //0  0  0
    //0  0  0
    //0  0  0
    //0  0  0

    //全一矩阵vector1
    val mo = DenseMatrix.ones[Int](5, 5)
    val m54 = DenseMatrix.ones[Int](5, 4)


    val m5: DenseMatrix[Int] = mo * 5

    //println(matrix *  m54)


    //E矩阵
    val me = DenseMatrix.eye[Int](5)
    //1  0  0  0  0
    //0  1  0  0  0
    //0  0  1  0  0
    //0  0  0  1  0
    //0  0  0  0  1


    println(me * m54)
    //1  1  1  1
    //1  1  1  1
    //1  1  1  1
    //1  1  1  1
    //1  1  1  1

    //按行创建矩阵
    val dm1 = DenseMatrix((1, 2, 3, 4, 6), (5, 6, 7, 8, 9))
    val dm2 = DenseMatrix(Array(1, 2, 3, 4, 5), Array(1, 2, 3, 4, 9))

    println(dm1)
    //1  2  3  4  6
    //5  6  7  8  9

    //随机生成矩阵
    val md = DenseMatrix.rand(2, 3)

    println(md)
    //0.2959375815715777  0.9843539359545022  0.6665200410800738
    //0.5337065787313775  0.3430473156216234  0.4049944313755576

    val mt = DenseMatrix.tabulate(3, 2) {
      case (x, y) => {
          println(x + " : " + y)
        x + y
      }
    }
    //0 : 0
    //1 : 0
    //2 : 0
    //0 : 1
    //1 : 1
    //2 : 1

    println(mt)
    //0  1
    //1  2
    //2  3
  }
}
